import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 防止同一路由多次点击报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const discovery = () => import('../views/discovery/index.vue')
const recommend = () => import('../views/recommend/index.vue')
const newMusic = () => import('../views/newmusic/index.vue')
const newMV = () => import('../views/newmv/index.vue')

const routes = [
  {
    path: '/',
    redirect: '/discovery',
  },
  {
    path: '/discovery',
    component: discovery,
  },
  {
    path: '/recommend',
    component: recommend,
  },
  {
    path: '/newmusic',
    component: newMusic,
  },
  {
    path: '/newmv',
    component: newMV,
  },
]

const router = new VueRouter({
  routes,
  mode: 'history',
})

export default router
